#region Copyright Notice
// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 
#endregion
namespace AbstractClass.Collections.Generic
{
    /// <summary>
    /// Represents a node associated with an elements in the <see cref = "SkipList&lt;T&gt;" />.
    /// </summary>
    /// <typeparam name="T">The type of the data associated with th <see cref = "SkipListNode&lt;T&gt;" /></typeparam>
    public class SkipListNode<T>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SkipListNode&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="height">The height associated with this node.</param>
        public SkipListNode(int height)
        {
            Neighbors = new SkipListNodeCollection<T>(height);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SkipListNode&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="value">The value associated with this instance.</param>
        /// <param name="height">The height of the node in <see cref = "SkipList&lt;T&gt;" />.</param>
        public SkipListNode(T value, int height)
        {
            Neighbors = new SkipListNodeCollection<T>(height);
            Value = value;
        }

        /// <summary>
        /// Gets or sets the value associated with this instance.
        /// </summary>
        /// <value>The value associated with this instance.</value>
        public T Value { get; set; }

        /// <summary>
        /// Gets or sets the neighborhood nodes of this instance.
        /// </summary>
        /// <value>The neighborhood nodes of this instance.</value>
        public SkipListNodeCollection<T> Neighbors { get; set; }

        /// <summary>
        /// Gets the height associated with the node.
        /// </summary>
        /// <value>The height associated with the node.</value>
        public int Height
        {
            get { return Neighbors.Count; }
        }

        /// <summary>
        /// Gets or sets the neighborhood <see cref="SkipListNode&lt;T&gt;"/> at the specified index.
        /// </summary>
        /// <value>The neighborhood node of this instance.</value>
        public SkipListNode<T> this[int index]
        {
            get { return Neighbors[index]; }
            set { Neighbors[index] = value; }
        }

        /// <summary>
        /// Increments the height in the neighborhood.
        /// </summary>
        protected internal void IncrementHeight()
        {
            Neighbors.IncrementHeight();
        }

        /// <summary>
        /// Decrements the height in the neighborhood.
        /// </summary>
        protected internal void DecrementHeight()
        {
            Neighbors.DecrementHeight();
        }
    }
}